﻿using System.Collections.Generic;
using XLua;
#if USE_UNI_LUA
using LuaAPI = UniLua.Lua;
using RealStatePtr = UniLua.ILuaState;
using LuaCSFunction = UniLua.CSharpFunctionDelegate;
#else
using LuaAPI = XLua.LuaDLL.Lua;
using RealStatePtr = System.IntPtr;
using LuaCSFunction = XLua.LuaDLL.lua_CSFunction;
#endif

namespace XLua.CSObjectWrap
{
    using Utils = XLua.Utils;

    public class UnityEngineKeyframeWrap
    {
        public static void __Register(RealStatePtr L)
        {
            ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
            System.Type type = typeof(UnityEngine.Keyframe);
            Utils.BeginObjectRegister(type, L, translator, 0, 0, 7, 7);

            Utils.RegisterFunc(L, Utils.GETTER_IDX, "time", _g_get_time);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "value", _g_get_value);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "inTangent", _g_get_inTangent);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "outTangent", _g_get_outTangent);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "inWeight", _g_get_inWeight);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "outWeight", _g_get_outWeight);
            Utils.RegisterFunc(L, Utils.GETTER_IDX, "weightedMode", _g_get_weightedMode);

            Utils.RegisterFunc(L, Utils.SETTER_IDX, "time", _s_set_time);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "value", _s_set_value);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "inTangent", _s_set_inTangent);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "outTangent", _s_set_outTangent);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "inWeight", _s_set_inWeight);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "outWeight", _s_set_outWeight);
            Utils.RegisterFunc(L, Utils.SETTER_IDX, "weightedMode", _s_set_weightedMode);

            Utils.EndObjectRegister(type, L, translator, null, null, null, null, null);

            Utils.BeginClassRegister(type, L, __CreateInstance, 1, 0, 0);

            Utils.EndClassRegister(type, L, translator);
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int __CreateInstance(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                if (
                    LuaAPI.lua_gettop(L) == 3
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3)
                )
                {
                    float _time = (float)LuaAPI.lua_tonumber(L, 2);
                    float _value = (float)LuaAPI.lua_tonumber(L, 3);

                    var gen_ret = new UnityEngine.Keyframe(_time, _value);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    LuaAPI.lua_gettop(L) == 5
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5)
                )
                {
                    float _time = (float)LuaAPI.lua_tonumber(L, 2);
                    float _value = (float)LuaAPI.lua_tonumber(L, 3);
                    float _inTangent = (float)LuaAPI.lua_tonumber(L, 4);
                    float _outTangent = (float)LuaAPI.lua_tonumber(L, 5);

                    var gen_ret = new UnityEngine.Keyframe(_time, _value, _inTangent, _outTangent);
                    translator.Push(L, gen_ret);

                    return 1;
                }
                if (
                    LuaAPI.lua_gettop(L) == 7
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 5)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 6)
                    && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 7)
                )
                {
                    float _time = (float)LuaAPI.lua_tonumber(L, 2);
                    float _value = (float)LuaAPI.lua_tonumber(L, 3);
                    float _inTangent = (float)LuaAPI.lua_tonumber(L, 4);
                    float _outTangent = (float)LuaAPI.lua_tonumber(L, 5);
                    float _inWeight = (float)LuaAPI.lua_tonumber(L, 6);
                    float _outWeight = (float)LuaAPI.lua_tonumber(L, 7);

                    var gen_ret = new UnityEngine.Keyframe(
                        _time,
                        _value,
                        _inTangent,
                        _outTangent,
                        _inWeight,
                        _outWeight
                    );
                    translator.Push(L, gen_ret);

                    return 1;
                }

                if (LuaAPI.lua_gettop(L) == 1)
                {
                    translator.Push(L, default(UnityEngine.Keyframe));
                    return 1;
                }
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return LuaAPI.luaL_error(L, "invalid arguments to UnityEngine.Keyframe constructor!");
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_time(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                LuaAPI.lua_pushnumber(L, gen_to_be_invoked.time);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_value(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                LuaAPI.lua_pushnumber(L, gen_to_be_invoked.value);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_inTangent(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                LuaAPI.lua_pushnumber(L, gen_to_be_invoked.inTangent);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_outTangent(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                LuaAPI.lua_pushnumber(L, gen_to_be_invoked.outTangent);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_inWeight(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                LuaAPI.lua_pushnumber(L, gen_to_be_invoked.inWeight);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_outWeight(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                LuaAPI.lua_pushnumber(L, gen_to_be_invoked.outWeight);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _g_get_weightedMode(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                translator.Push(L, gen_to_be_invoked.weightedMode);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 1;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_time(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                gen_to_be_invoked.time = (float)LuaAPI.lua_tonumber(L, 2);

                translator.Update(L, 1, gen_to_be_invoked);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_value(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                gen_to_be_invoked.value = (float)LuaAPI.lua_tonumber(L, 2);

                translator.Update(L, 1, gen_to_be_invoked);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_inTangent(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                gen_to_be_invoked.inTangent = (float)LuaAPI.lua_tonumber(L, 2);

                translator.Update(L, 1, gen_to_be_invoked);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_outTangent(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                gen_to_be_invoked.outTangent = (float)LuaAPI.lua_tonumber(L, 2);

                translator.Update(L, 1, gen_to_be_invoked);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_inWeight(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                gen_to_be_invoked.inWeight = (float)LuaAPI.lua_tonumber(L, 2);

                translator.Update(L, 1, gen_to_be_invoked);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_outWeight(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                gen_to_be_invoked.outWeight = (float)LuaAPI.lua_tonumber(L, 2);

                translator.Update(L, 1, gen_to_be_invoked);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }

        [MonoPInvokeCallbackAttribute(typeof(LuaCSFunction))]
        static int _s_set_weightedMode(RealStatePtr L)
        {
            try
            {
                ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);

                UnityEngine.Keyframe gen_to_be_invoked;
                translator.Get(L, 1, out gen_to_be_invoked);
                UnityEngine.WeightedMode gen_value;
                translator.Get(L, 2, out gen_value);
                gen_to_be_invoked.weightedMode = gen_value;

                translator.Update(L, 1, gen_to_be_invoked);
            }
            catch (System.Exception gen_e)
            {
                return LuaAPI.luaL_error(L, "c# exception:" + gen_e);
            }
            return 0;
        }
    }
}
